package com.foreveredu.erlms.persist.hibernate;

import java.util.List;

import com.foreveredu.erlms.domain.Clazz;
import com.foreveredu.erlms.persist.IClazzDao;

public class HibernateClazzDao extends HibernateAbstractDao<Clazz, Integer>
		implements IClazzDao {

	private static final long serialVersionUID = 1L;

	public HibernateClazzDao() {
		super(Clazz.class);
	}

	//查找某专业下的所有班级
	@SuppressWarnings("unchecked")
	@Override
	public List<Clazz> findClazzsOfMajor(int majorId) {
		return this.getHibernateTemplate().find("from Clazz c where c.major.id = ? order by c.clazzId desc", majorId);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Clazz findClazzByClazzId(String clazzId) {
		List<Clazz> clazzList = this.getHibernateTemplate().find(
				"from Clazz clazz  where clazz.clazzId = ?", clazzId);
		Clazz clazz = null;
		if (clazzList != null && clazzList.size() > 0) {
			clazz = clazzList.get(0);
		}
		return clazz;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Clazz> findClazzsByDept(int deptId) {
		return this.getHibernateTemplate().find("from Clazz c where c.dept.id = ? order by c.clazzId desc", deptId);
	}
	
}
